﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Print_Phuluc2e : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //_dbDataContext _db = new _dbDataContext();
        //var list = PageURL.ListDsDaoTao;
        //var listdanhsachdangky = PageURL.ListDsDangKy;
        //string st = "";
        //st += "<td>1</td>";
        //for (int i = 1; i <= 3; i++)
        //{
        //    //tính lới 1
        //    var listlop1 = list.Where(r => r.TenLopID == i);
        //    st += "<td></td>";
        //    //Tính cấp tỉnh
        //    //Tổng số lớp
        //    st += "<td>" + listlop1.Where(r => r.DonViToChuc.Substring(0, 3) == "TDB").Count().ToString() + "</td>";
        //    //Tinh so can bo tham gia
        //    st += "<td>" + (from r in listlop1 where r.DonViToChuc.Substring(0, 3) == "TDB" join c in listdanhsachdangky on r.ID equals c.MaLopID select r).Count().ToString() + "</td>";
        //    //Tính cấp huyen
        //    //Tổng số lớp
        //    st += "<td>" + listlop1.Where(r => r.DonViToChuc.Substring(0, 3) == "CSD").Count().ToString() + "</td>";
        //    //Tinh so can bo tham gia
        //    st += "<td>" + (from r in listlop1 where r.DonViToChuc.Substring(0, 3) == "CSD" join c in listdanhsachdangky on r.ID equals c.MaLopID select r).Count().ToString() + "</td>";
        //    //Tính cấp xa
        //    //Tổng số lớp
        //    st += "<td>" + listlop1.Where(r => r.DonViToChuc.Substring(0, 3) == "DCS" || r.DonViToChuc.Substring(0, 3) == "CDC").Count().ToString() + "</td>";
        //    //Tinh so can bo tham gia
        //    st += "<td>" + (from r in listlop1 where r.DonViToChuc.Substring(0, 3) == "CSD" || r.DonViToChuc.Substring(0, 3) == "CDC" join c in listdanhsachdangky on r.ID equals c.MaLopID select r).Count().ToString() + "</td>";
        //}
        ////thong ke can bo doan duoc dao tao ly luan chinh tri.
        //var listdscanbodoan = from p in _db.tblDoanViens join c in _db.tblCongTacDoans on p.MaDonVien equals c.MaDoanVien select p;
        //st += "<td>" + listdscanbodoan.Where(r => r.tblQuanHeXaHoi.LyLuanChinhTriID == 76 || r.tblQuanHeXaHoi.LyLuanChinhTriID == 108).Count().ToString() + "</td>";//cu nhan va cao cap
        //st += "<td>" + listdscanbodoan.Where(r => r.tblQuanHeXaHoi.LyLuanChinhTriID == 21).Count().ToString() + "</td>";//trung cap
        if (Session["PhuLuc2ePrint"] != null)
        {
            lblsummary.Text = Session["PhuLuc2ePrint"].ToString();
            try
            {
                Response.Clear();
                Response.AddHeader("content-disposition", "attachment; filename=FileName.xls");
                Response.Charset = "";
                Response.ContentType = "application/vnd.xls";
                System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                grid_Detail.RenderControl(htmlWrite);
                Response.Write(stringWrite.ToString());
                Response.End();
                Response.Redirect("javascript:window.close()");
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "')</script>");
            }
            Session.Remove("PhuLuc2ePrint");
        }
    }
}